﻿<template>
  <div class="container" style="width:99%;margin-top:-25px;">
    <!-- 查询条件 -->
    <div class="query-box">
      <el-form :model="queryBox" status-icon ref="queryBox">
        <div class="schoolBoxCont">
          <div class="schoolBoxContItem">
            <el-form-item label prop="name">
              <div class="schoolBoxContItemTitle">
                学校名称
              </div>
              <div class="schoolBoxContItemInput">
                <el-input
                  clearable
                  v-model="queryBox.name"
                  placeholder="学校名称"
                >
                </el-input>
              </div>
            </el-form-item>
          </div>
          <div class="schoolBoxContItem">
            <el-form-item label prop="name">
              <div class="schoolBoxContItemTitle">
                大区经理
              </div>
              <div class="schoolBoxContItemInput">
                <el-select
                  v-model="queryBox.belongToId"
                  filterable
                  placeholder="请选择"
                  value-key="id"
                  style="width: 100%;"
                >
                  <el-option
                    v-for="item in userName"
                    :key="item.id"
                    :label="item.realName"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </div>
            </el-form-item>
          </div>
          <div class="schoolBoxContItem">
            <el-form-item label prop="name">
              <div class="schoolBoxContItemTitle">
                三级部门
              </div>
              <div class="schoolBoxContItemInput">
                <el-select
                  v-model="queryBox.thirdLevelDepartment"
                  clearable
                  filterable
                  @change="changeThree"
                >
                  <el-option
                    v-for="item in threeDept"
                    :key="item.id"
                    :label="item.deptName"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </div>
            </el-form-item>
          </div>

          <!-- <div class="schoolBoxContItem">
            <el-form-item label prop="name">
              <div class="schoolBoxContItemTitle">
                三方分成比例
              </div>
              <div class="schoolBoxContItemInput">
                <el-input
                  clearable
                  v-model="queryBox.thirdProportion"
                  placeholder="三方分成比例"
                  @change="Proportion"
                >
                </el-input>
              </div>
            </el-form-item>
          </div> -->
          <div class="schoolBoxContItem">
            <el-form-item label prop="name">
              <div class="schoolBoxContItemTitle">
                三方姓名
              </div>
              <div class="schoolBoxContItemInput">
                <el-input
                  clearable
                  v-model="queryBox.thirdName"
                  placeholder="三方姓名"
                >
                </el-input>
              </div>
            </el-form-item>
          </div>
          <div class="schoolBoxContItem">
            <el-form-item label prop="name">
              <div class="schoolBoxContItemTitle">
                意向程度
              </div>
              <div class="schoolBoxContItemInput">
                <el-select
                  clearable
                  filterable
                  v-model="queryBox.type"
                  filterable
                >
                  <el-option
                    v-for="item in student_type_options"
                    :key="item.key"
                    :label="item.value"
                    :value="item.key"
                  ></el-option>
                </el-select>
              </div>
            </el-form-item>
          </div>
          <div class="schoolBoxContItem">
            <el-form-item label prop="name">
              <div class="schoolBoxContItemTitle">
                是否报备
              </div>
              <div class="schoolBoxContItemInput">
                <el-select
                  clearable
                  filterable
                  v-model="queryBox.isRecord"
                  filterable
                >
                  <el-option
                    v-for="item in isRecord_type_options"
                    :key="item.key"
                    :label="item.value"
                    :value="item.key"
                  ></el-option>
                </el-select>
              </div>
            </el-form-item>
          </div>
          <div class="schoolBoxContItem">
            <el-form-item label prop="name">
              <div class="schoolBoxContItemTitle">
                所在地区：
              </div>
              <div class="schoolBoxContItemInput" style="width:300px">
                <el-cascader
                  clearable
                  style="width:100% !important"
                  size="large"
                  :options="options"
                  v-model="selectedOptions"
                ></el-cascader>
              </div>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <div class="from-btns">
        <kt-button
          :label="$t('action.reset')"
          perms="true"
          type="primary"
          @click="reset('queryBox')"
        />
        <kt-button
          :label="$t('action.search')"
          perms="true"
          type="primary"
          @click="get_subcentersearch"
        />
      </div>
    </div>
    <!-- 批量删除按钮 -->
    <!-- <div class="add-btns fl">
      <kt-button
        label="移入客户公海"
        perms="directCampCenter:myschool:delete"
        :size="size"
        type="danger"
        @click="handleBatchDelete"
        :disabled="this.selections.length === 0"
        style="float:left;"
      />
    </div> -->
    <div class="fr" style="margin-bottom:20px">
      <!-- <kt-button
        :label="$t('action.download-tmpl')"
        type="primary"
        perms="directCampCenter:myschool:download"
        @click="downloadTmpl"
      ></kt-button>
      <kt-button
        :label="$t('action.batchimport')"
        type="primary"
        perms="directCampCenter:myschool:batchimport"
        @click="customerManagerImport"
      ></kt-button> -->
      <el-button type="primary" @click="openAsking" size="mini"
        >学校查询</el-button
      >
      <!-- <kt-button
        label="报备学校"
        type="primary"
        perms="directCampCenter:myschool:add"
        @click="handleNewADD"
      ></kt-button> -->
    </div>
    <!-- 查重 -->
    <Checkrepeat
      @colsePop="colsePop"
      @openAsking="openAsking"
      :checkrepeatShow="checkrepeatShow"
      :checkloading="checkloading"
    ></Checkrepeat>
    <!--表格内容栏-->
    <div class="btn">
      <Crm-table
        @selectionChange="selectionChange"
        class="table-width"
        SchoolAudit
        width="400"
        permsAudit="DirectCampCenter:SchoolAudit:audit"
        permsSee="DirectCampCenter:SchoolAudit:see"
        :data="pageResult"
        :columns="columns"
        :loading="loading"
        @findPage="findPage"
        @changeSwitch="changeSwitch"
        @handleEdit="handleEdit"
        @handleSee="handleSee"
        @handleFollow="handleFollow"
        @handleReport="handleReport"
        @handleAudit='handleAudit'
        @handleAudit2='handleAudit2'
      ></Crm-table>
    </div>
    <!-- 报备 -->
    <el-dialog
      :title="recordData.name"
      width="70%"
      :visible.sync="reportShow"
      :close-on-click-modal="false"
    >
      <div class="second-contain-box ma school-pop second-contain-box2">
        <el-row>
          <el-col :span="3">
            <el-col :span="16">
              <i>拜访次数：</i>
            </el-col>
            <el-col :span="8">
              <span>{{ recordData.visitNum }}</span>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="8">
              <i><em style="color:red">*</em> 拜访/宴请/参会时间：</i>
            </el-col>
            <el-col :span="14">
              <!-- <el-date-picker
                v-model="recordData.trackingDate"
                style="width:100%;"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
                type="date"
                placeholder="选择日期"
              >
              </el-date-picker> -->
              <el-date-picker
                v-model="recordData.trackingDate"
                type="datetimerange"
                style="margin-top:-10px"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
              ></el-date-picker>
            </el-col>
          </el-col>
          <el-col :span="9">
            <el-col :span="6">
              <i><em style="color:red">*</em> 报备类别：</i>
            </el-col>
            <el-col :span="18">
              <el-select
                style="width:100%;margin-top:-10px"
                v-model="recordData.recordType"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in school_recordType_options"
                  :key="item.value"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-col :span="24">
              <el-col :span="3">
                <i><em style="color:red">*</em> 跟踪情况：</i>
              </el-col>
              <el-col :span="21">
                <el-input
                  style="width:100%"
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="recordData.recordContent"
                ></el-input>
              </el-col>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-col :span="24">
              <el-col :span="3">
                <i><em style="color:red">*</em> 下次跟进计划：</i>
              </el-col>
              <el-col :span="21">
                <el-input
                  style="width:100%"
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="recordData.nextPlan"
                ></el-input>
              </el-col>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-col :span="24">
              <el-col :span="3">
                <i><em style="color:red">*</em> 项目主要障碍：</i>
              </el-col>
              <el-col :span="21">
                <el-input
                  style="width:100%"
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="recordData.majorDifficulty"
                ></el-input>
              </el-col>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-col :span="24">
              <el-col :span="3">
                <i><em style="color:red">*</em> 需要的支持：</i>
              </el-col>
              <el-col :span="21">
                <el-input
                  style="width:100%"
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="recordData.neededSupport"
                ></el-input>
              </el-col>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-col :span="24">
              <el-col :span="3">
                <i><em style="color:red">*</em> 竞争对手：</i>
              </el-col>
              <el-col :span="21">
                <el-input
                  style="width:100%"
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="recordData.competitor"
                ></el-input>
              </el-col>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-col :span="24">
              <el-col :span="3">
                <i><em style="color:red">*</em> 收费标准：</i>
              </el-col>
              <el-col :span="21">
                <el-input
                  style="width:100%"
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="recordData.charge"
                ></el-input>
              </el-col>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-col :span="6" style="margin-top:15px">
              <i><em style="color:red">*</em> 预计成交时间：</i>
            </el-col>
            <el-col :span="16">
              <el-date-picker
                v-model="recordData.expectedClosingDate"
                style="width:100%;"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="6" style="margin-top:15px">
              <i><em style="color:red">*</em> 计划招生人数：</i>
            </el-col>
            <el-col :span="18">
              <el-input
                placeholder="请输入内容"
                v-model="recordData.plannedPeopleNum"
              ></el-input>
            </el-col>
          </el-col>
        </el-row>
      </div>
      <kt-button
        class="stu-btn"
        :label="$t('action.save')"
        perms="true"
        size="medium"
        type="primary"
        @click="handleSaveRecord()"
      />
      <p class="tracking-tit">跟进情况</p>
      <Crm-table
        :showBatchDelete="showBatchDelete"
        class="tracking-table"
        :data="detailRecordInfoData"
        :columns="columns3"
        @findPage3="findPage3"
        :loading="loading"
      >
      </Crm-table>
    </el-dialog>
    <!-- 跟进 -->
    <el-dialog
      :title="saveData.name"
      width="70%"
      :visible.sync="addFollow"
      :close-on-click-modal="false"
    >
      <div class="second-contain-box ma school-pop">
        <el-row>
          <el-col :span="12">
            <el-col :span="12">
              <i style="margin-top:0">跟进次数：{{ saveData.trackingNum }}</i>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="8">
              <i style="margin-top:0">跟进时间：</i>
            </el-col>
            <el-col :span="16">
              <span>{{ saveData.trackingDate }}</span>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-col :span="6">
              <i>联系人：</i>
            </el-col>
            <el-col :span="16">
              <el-input
                placeholder="请输入内容"
                v-model="saveData.contactTrack"
              ></el-input>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="6">
              <i>沟通形式：</i>
            </el-col>
            <el-col :span="18">
              <el-select
                style="width:100%"
                v-model="saveData.communicationType"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in student_communication_type"
                  :key="item.value"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-col :span="6">
              <i>客户类型：</i>
            </el-col>
            <el-col :span="16">
              <el-select
                style="width:100%"
                :disabled="typeDisabled"
                v-model="saveData.type"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in student_type_options"
                  :key="item.value"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="6">
              <i>客户进展：</i>
            </el-col>
            <el-col :span="18">
              <el-select
                style="width:100%"
                :disabled="selectDisabled"
                v-model="saveData.progress"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in student_progress_options"
                  :key="item.value"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-col :span="24">
              <el-col :span="3">
                <i>沟通内容：</i>
              </el-col>
              <el-col :span="21">
                <el-input
                  style="width:100%"
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="saveData.communicationContent"
                ></el-input>
              </el-col>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <i style="margin-top:5%">跟进人：{{ trackingPeople }}</i>
          </el-col>
          <el-col :span="12">
            <el-col :span="8">
              <i>下次跟进日期：</i>
            </el-col>
            <el-col :span="16">
              <el-date-picker
                style="width:100%"
                v-model="saveData.nextTrackingDate"
                type="datetime"
                placeholder="选择日期时间"
                :default-time="mytime"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
                :picker-options="pickerOptions"
              ></el-date-picker>
            </el-col>
          </el-col>
        </el-row>
      </div>
      <kt-button
        class="stu-btn"
        :label="$t('action.save')"
        perms="true"
        size="medium"
        type="primary"
        @click="handleSave()"
      />
      <p class="tracking-tit">跟进情况</p>
      <Crm-table
        :showBatchDelete="showBatchDelete"
        class="tracking-table"
        :data="stuqueryTrackingData"
        :columns="columns2"
        @findPage2="findPage2"
        :loading="loading"
      >
      </Crm-table>
    </el-dialog>
    <!--导入-->
    <el-dialog
      :title="'批量导入'"
      width="30%"
      :visible.sync="uploadOem"
      :close-on-click-modal="false"
    >
      <el-form :model="form">
        <el-form-item>
          <el-upload
            ref="uploadExcel"
            :action="uploadUrl"
            :limit="limitNum"
            :auto-upload="false"
            accept=".xls"
            :before-upload="beforeUploadFile"
            :on-change="fileChange"
            :on-exceed="exceedFile"
            :on-success="handleSuccess"
            :on-error="handleError"
            :file-list="fileList"
            :on-remove="handleRemove"
          >
            <el-button size="small" plain>选择文件上传</el-button>
            <div slot="tip" class="el-upload__tip">
              只能上传xls(Excel97-2004)文件
            </div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="size" @click.native="uploadOem = false">{{
          $t("action.cancel")
        }}</el-button>
        <el-button :size="size" type="primary" @click.native="uploadFile">{{
          $t("立即上传")
        }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import KtButton from "@/views/Core/KtButton";
import StTable from "@/views/Core/StTable";
import CrmTable from "@/views/Core/CrmTable";
import CrmSwitch from "@/views/Core/CrmSwitch";
import { CodeToText } from "element-china-area-data";
import { baseUrl } from "@/utils/global";
import { regionDataPlus } from "element-china-area-data";
import axios from "axios";
import Checkrepeat from "@/views/Core/Checkrepeat";
import Cookies from "js-cookie";
export default {
  name: "School",
  components: {
    PopupTreeInput,
    CrmTable,
    KtButton,
    CrmSwitch,
    Checkrepeat
  },
  data() {
    return {
      isShowFlag: 0, //0:初始化部门、人员不显示  1:部门显示 2：人员显示
      showBatchDelete: false,
      mytime: "",
      size: "mini",
      selectDisabled: false, //跟进弹窗客户进展状态
      typeDisabled: false,
      schoolSectionArr: [], //学段数组
      filters: {
        name: ""
      },
      uploadOem: false, //文件上传
      limitNum: 1, //上传最大个数
      form: {
        file: ""
      },
      isTodayTracking: "",
      fileList: [],
      uploadUrl: baseUrl + "/file/upload", //文件上传地址
      downloadTmplUrl: baseUrl + "/template/schoolImportTemplate.xlsx", //模板下载地址
      // 查询条件
      student_data_from_options: [
        {
          label: " ",
          key: " "
        }
      ],
      // 客户跟进数据
      stuqueryTrackingData: {
        content: []
      },
      // 报备数据
      detailRecordInfoData: {
        content: []
      },
      // 查询条件
      student_data_from_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_type_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_progress_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_data_from_type_options: [
        {
          label: " ",
          key: " "
        }
      ],

      isRecord_type_options: [
        {
          key: "1",
          value: "已报备"
        },
        {
          key: "2",
          value: "未报备"
        }
      ],
      isTodayTracking_options: [
        {
          value: "是",
          label: "1"
        }
      ],

      student_level_cache_options: [
        {
          key: " ",
          value: " "
        }
      ],
      createDateArr: [], // 创建时间数组
      trackingDateArr: [], //跟进时间数组
      student_communication_type: [],
      queryBox: {
        name: "",
        contact: "",
        peopleNum: "",
        schoolSystem: "",
        type: "",
        duty: "",
        phone: "",
        thirdProportion: 0,
        thirdName: "",
        thirdPhone: "",
        thirdContractSignedDate: "",
        thirdContractEndDate: "",
        paymentSituation: "",
        feastNum: "",
        mettingNum: "",
        visitNum: "",
        thirdLevelDepartment: "",
        isRecord: ""
      },
      columns: [
        { type: "index", label: "序号", minWidth: 50 },
        { prop: "name", label: "学校名称", minWidth: 180 },
        { prop: "peopleNum", label: "学校人数", minWidth: 100 },
        { prop: "contact", label: "学校负责人", minWidth: 80 },
        { prop: "duty", label: "职位", minWidth: 80 },
        { prop: "phone", label: "手机", minWidth: 100 },
        { prop: "thirdProportion", label: "三方分成比例", minWidth: 100 },
        { prop: "thirdName", label: "三方姓名", minWidth: 100 },
        { prop: "thirdPhone", label: "三方手机", minWidth: 100 },
        {
          prop: "thirdContractSignedDate",
          label: "三方合同签署时间",
          minWidth: 120
        },
        {
          prop: "thirdContractEndDate",
          label: "三方合同到期时间",
          minWidth: 120
        },
        { prop: "paymentSituation", label: "回款情况", minWidth: 100 },
        { prop: "feastNum", label: "宴请次数", minWidth: 100 },
        { prop: "mettingNum", label: "参会次数", minWidth: 100 },
        { prop: "visitNum", label: "拜访次数", minWidth: 100 },
        { prop: "record", label: "是否报备", minWidth: 100 },
        { prop: "auditStatusStr", label: "审核状态", minWidth: 100 },
        { prop: "diqu", label: "地区", minWidth: 190 },
        {
          prop: "createDate",
          sortable: "true",
          label: "创建时间",
          minWidth: 140
        }
        // {
        //   prop: "trackingDate",
        //   sortable: "true",
        //   label: "最新跟进时间",
        //   minWidth: 140
        // }
      ],
      columns2: [
        { type: "index", label: "序号", minWidth: 10 },
        { prop: "trackingDate", label: "跟进时间", minWidth: 100 },
        { prop: "contactTrack", label: "联系人", minWidth: 50 },
        { prop: "typeTrack", label: "客户类型", minWidth: 80 },
        { prop: "progressTrack", label: "客户进展", minWidth: 50 },
        { prop: "communicationType", label: "沟通形式", minWidth: 50 },
        { prop: "communicationContent", label: "沟通内容", minWidth: 120 },
        { prop: "nextTrackingDateDetail", label: "下次跟进时间", minWidth: 100 }
      ],
      columns3: [
        { type: "index", label: "序号", minWidth: 10 },
        { prop: "trackingDate", label: "拜访/宴请/参会时间", minWidth: 100 },
        { prop: "recordType", label: "报备类别", minWidth: 100 },
        { prop: "recordContent", label: "跟踪情况", minWidth: 80 },
        { prop: "nextPlan", label: "下次跟进计划", minWidth: 100 },
        { prop: "majorDifficulty", label: "项目主要障碍", minWidth: 100 },
        { prop: "neededSupport", label: "需要的支持", minWidth: 120 },
        { prop: "competitor", label: "竞争对手", minWidth: 100 },
        { prop: "charge", label: "收费标准", minWidth: 100 },
        { prop: "expectedClosingDate", label: "预计成交时间", minWidth: 100 },
        { prop: "plannedPeopleNum", label: "计划招生人数", minWidth: 100 }
      ],
      pageResult: {
        content: []
      },
      operation: false, // true:新增, false:编辑
      batchdistribution: false, //显示批量分配弹窗
      selectionsLength: "",
      selections: [], //选中列表集合
      ids: [], //分配ID集合
      deptData: [], //部门树
      deptTree: {
        label: "deptName",
        children: "children"
      },
      addFollow: false, //显示跟进窗口
      deptinputValue: "",
      // 划分方式
      deptmodeoptions: [
        {
          label: "分配至部门",
          value: "11"
        },
        {
          label: "分配至个人",
          value: "9"
        }
      ],

      deptuseroption: [], //部门用户
      addstuformData: {},
      deptmodeoptionsValue: "",

      AllotData: {
        assignType: 2,
        schoolIds: "",
        thirdLevelDepartment: "",
        belongToId: "",
        belong_to_type: ""
      },
      // 地区
      options: regionDataPlus,
      selectedOptions: [],
      saveData: {
        type: "",
        dataFrom: "",
        progress: "",
        code: "",
        name: "",
        schoolSection: "",
        belongToId: "",
        thirdPatry: "",
        isLock: "",
        createDateStart: "", //创建开始时间
        createDateEnd: "", //创建结束时间
        trackingDateStart: "", //最新跟进开始时间
        trackingDateEnd: "", //最新跟进结束时间
        orderName: "",
        orderType: "",
        id: "",
        progress: "",
        belongToName: "",
        belongToId: Cookies.get("userId"),
        communicationType: ""
      },
      trackingPeople: Cookies.get("realName"),
      loading: false, // 加载标识
      // 限制跟进时间
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7; //如果没有后面的-8.64e7就是不可以选择今天的
        }
      },
      pageRequest2: {
        pageNum: 1,
        pageSize: 10
      },
      checkrepeatShow: false,
      checkloading: false,
      checkMessage: "",
      isLoadingSuccess: false,
      reportShow: false,
      recordData: {
        trackingDate: "",
        expectedClosingDate: ""
      },
      queryTrackingRecordData: {},
      threeDept: [],
      school_recordType_options: [],
      userName: []
    };
  },
  methods: {
    // 客户类型
    get_student_type() {
      this.student_type_options = JSON.parse(
        localStorage.getItem("schoolType")
      );
    },

    // 客户来源
    get_student_data_from() {
      this.student_data_from_options = JSON.parse(
        localStorage.getItem("schoolSource")
      );
    },
    get_dataTime() {
      let dateTime = new Date();
      this.saveData.trackingDate = this.dateFormat(dateTime);
      let mytime = dateTime.toLocaleTimeString("chinese", { hour12: false }); //获取当前时间
      this.mytime = mytime;
    },
    // 获取方式
    get_student_data_from_type() {
      this.student_data_from_type_options = JSON.parse(
        localStorage.getItem("schoolDataFromType")
      );
    },

    // 客户进展
    get_student_progress() {
      this.student_progress_options = JSON.parse(
        localStorage.getItem("schoolProgress")
      );
    },

    student_progress_change(value) {
      this.queryBox.student_progressValue = value.toString();
    },

    // 学段
    get_level_cache() {
      this.student_level_cache_options = JSON.parse(
        localStorage.getItem("schoolSection")
      );
    },

    // 获取分页数据
    findPage: function(data) {
      if (data !== null) {
        this.loading = true;
        this.pageRequest = data.pageRequest;
      }

      //如果创建时间查询的时候选择了，给查询参数赋值
      if (this.createDateArr.length > 0) {
        this.queryBox.createDateStart = this.createDateArr[0];
        this.queryBox.createDateEnd = this.createDateArr[1];
      }

      //如果跟进时间查询的时候选择了，给查询参数赋值
      if (this.trackingDateArr.length > 0) {
        this.queryBox.trackingDateStart = this.trackingDateArr[0];
        this.queryBox.trackingDateEnd = this.trackingDateArr[1];
      }
      // 查询审核中的学校
      this.queryBox.auditStatus=2
      // this.queryBox.queryInterface = 4;
      this.queryBox.pageNum = this.pageRequest.pageNum;
      this.queryBox.pageSize = this.pageRequest.pageSize;
      if (this.schoolSectionArr.length > 0) {
        this.queryBox.schoolSection = this.schoolSectionArr.join(",");
      } else if (this.schoolSectionArr.length == 0) {
        this.queryBox.schoolSection = "";
      }
      this.$api.school
        .cusomerschoolList(this.queryBox)
        .then(res => {
          let content = { content: res.listSchoolInfo, totalSize: res.total };
          this.pageResult = content;
          this.pageResult.content.forEach(item => {
            item.thirdProportion = item.thirdProportion + "%";
            // 去掉时间的时分秒
            item.thirdContractSignedDate = /\d{4}-\d{1,2}-\d{1,2}/g.exec(
              item.thirdContractSignedDate
            );
            item.thirdContractEndDate = /\d{4}-\d{1,2}-\d{1,2}/g.exec(
              item.thirdContractEndDate
            );
            //转换地区
            if (
              (item.province == null && item.city == null) ||
              (item.province == "null" && item.city == "null")
            ) {
              item.diqu = "";
            } else {
              item.diqu =
                CodeToText[item.province] +
                CodeToText[item.city] +
                CodeToText[item.area];
            }
            // 是否报备
            if (item.isRecord == 1) {
              item.record = "已报备";
            } else {
              item.record = "未报备";
            }
            // 审核状态  1: 未提交  2:审核中 3:审核通过  4:审核驳回
            if (item.auditStatus == 1) {
              item.auditStatusStr = "未提交";
            } 
            if (item.auditStatus == 2) {
              item.auditStatusStr = "审核中";
            } 
            if (item.auditStatus == 3) {
              item.auditStatusStr = "审核通过";
            } 
            if (item.auditStatus == 4) {
              item.auditStatusStr = "审核驳回";
            } 
            if (item.auditStatus == 0) {
              item.auditStatusStr = "审核通过";
            } 
            //转换来源
            this.student_data_from_options.forEach(type_item => {
              if (type_item.key == item.dataFrom) {
                item.laiyuan = type_item.value;
              }
            });
            //转换客户类型
            this.student_type_options.forEach(type_item => {
              if (type_item.key == item.type) {
                item.type2 = item.type;
                item.type = type_item.value;
              }
            });

            //转换客户进展
            this.student_progress_options.forEach(type_item => {
              if (type_item.key == item.progress) {
                item.jinzhan = type_item.value;
              }
            });

            // 转换学段
            if (item.schoolSection != "" && item.schoolSection != null) {
              let schoolSection = item.schoolSection.split(",");
              let sectionStr = "";
              schoolSection.forEach((schoolSection, index) => {
                this.student_level_cache_options.forEach(level_cache => {
                  if (level_cache.key == schoolSection) {
                    sectionStr = sectionStr + level_cache.value + ",";
                  }
                });
              });
              item.xueDuan = sectionStr.substring(
                0,
                sectionStr.lastIndexOf(",")
              );
            }
          });

          this.loading = false;
        })
        .then(data != null ? data.callback : "");
    },

    // 查询学生跟进列表
    findPage2(data) {
      if (data !== null) {
        this.pageRequest2 = data.pageRequest;
      }
      this.$api.school
        .schooldetail({
          id: this.saveData.schoolId,
          pageSize: this.pageRequest2.pageSize,
          pageNum: this.pageRequest2.pageNum
        })
        .then(res => {
          let content = { content: res.trackLists, totalSize: res.total };
          this.stuqueryTrackingData = content;
          this.stuqueryTrackingData.content.forEach(item => {
            this.student_type_options.forEach(type_item => {
              if (type_item.key == item.typeTrack) {
                item.typeTrack = type_item.value;
              }
            });

            this.student_progress_options.forEach(progress_item => {
              if (progress_item.key == item.progressTrack) {
                item.progressTrack = progress_item.value;
              }
            });

            this.student_type_options.forEach(type_item => {
              if (type_item.key == item.customerType) {
                item.customerType = type_item.value;
              }
            });

            this.student_communication_type.forEach(communication_item => {
              if (communication_item.key == item.communicationType) {
                item.communicationType = communication_item.value;
              }
            });
          });
        })
        .then(data != null ? data.callback : "");
    },
    // 查询报备列表
    findPage3(data) {
      if (data !== null) {
        this.pageRequest3 = data.pageRequest;
      }
      this.$api.school
        .detailRecordInfo({
          id: this.recordData.schoolId,
          pageSize: this.pageRequest2.pageSize,
          pageNum: this.pageRequest2.pageNum
        })
        .then(res => {
          let content = { content: res.trackLists, totalSize: res.total };
          this.detailRecordInfoData = content;
          this.detailRecordInfoData.content.forEach(item => {
            this.school_recordType_options.forEach(type_item => {
              if (type_item.key == item.recordType) {
                item.recordType = type_item.value;
              }
            });
            item.trackingDate =
              item.trackingDateStart + "--" + item.trackingDateEnd;
          });
          console.log(this.detailRecordInfoData);
        })
        .then(data != null ? data.callback : "");
    },
    // 搜索
    get_subcentersearch() {
      this.loading = true;
      this.queryBox.province = this.selectedOptions[0];
      this.queryBox.city = this.selectedOptions[1];
      this.queryBox.area = this.selectedOptions[2];
      this.pageRequest.pageNum = 1;
      this.findPage(null);
    },

    // 重置
    reset(queryBox) {
      // this.$refs.queryBox.resetFields();
      this.queryBox.name = "";
      this.queryBox.contact = "";
      this.queryBox.peopleNum = "";
      this.queryBox.schoolSystem = "";
      this.queryBox.type = "";
      this.queryBox.duty = "";
      this.queryBox.phone = "";
      this.queryBox.thirdProportion = 0;
      this.queryBox.thirdName = "";
      this.queryBox.thirdPhone = "";
      this.queryBox.thirdContractSignedDate = "";
      this.queryBox.thirdContractEndDate = "";
      this.queryBox.paymentSituation = "";
      this.queryBox.feastNum = "";
      this.queryBox.mettingNum = "";
      this.queryBox.visitNum = "";
      this.queryBox.selectedOptions = [];
      this.queryBox.province = "";
      this.queryBox.thirdLevelDepartment = "";
      this.queryBox.belongToId = "";
      this.selectedOptions = [];
      this.queryBox.city = "";
      this.queryBox.area = "";
      this.queryBox.isRecord = "";
      this.pageRequest.pageNum = 1;

      this.findPage(null);
    },
    // 批量分配
    handlebatchdistribution(params) {
      this.batchdistribution = true;
      this.ids = [];
      let idstu = this.selections.map(item => item.id);
      this.ids = idstu;
    },

    // 批量分配提交
    batchdistributionsubmit() {
      this.AllotData.schoolIds = this.ids;
      this.$api.school.schoolAssign(this.AllotData).then(res => {
        if (res.result === 1) {
          this.$message({ message: res.msg, type: "success" });
          this.batchdistribution = false;
          this.findPage(null);
        } else {
          this.$message({ message: res.msg, type: "error" });
        }
      });
    },

    // 批量删除
    handleBatchDelete() {
      let schids = this.selections.map(item => item.id);
      this.$confirm(
        "确认将" + this.selections.length + "个客户移入到公海吗？",
        "提示",
        {}
      ).then(() => {
        this.editLoading = true;
        this.$api.school
          .removeTo({
            schoolIds: this.ids
            // dateType: 4
          })
          .then(res => {
            if (res.result == 1) {
              this.$message({ message: "删除成功", type: "success" });
              this.findPage(null);
            } else {
              this.$message({ message: "删除失败", type: "errory" });
            }
          });
      });
    },

    // 解锁锁定
    changeSwitch: function(data) {
      this.$api.school
        .schoolInfoLock({
          schoolId: data.row.id,
          isLock: data.row.isLock
        })
        .then(res => {
          if (res.result == 1) {
            this.$message({ message: res.msg, type: "success" });

            //执行查询接口，刷新列表信息
            this.queryBox.queryInterface = 4;
            this.queryBox.pageNum = this.pageRequest.pageNum;
            this.queryBox.pageSize = this.pageRequest.pageSize;
            this.$api.school
              .cusomerschoolList(this.queryBox)
              .then(res => {
                this.pageResult.content = res.listSchoolInfo;
              })
              .then(data != null ? data.callback : "");
          } else {
            this.$message({ message: res.msg, type: "error" });
          }
        });
    },

    // 批量导入
    customerManagerImport: function() {
      this.uploadOem = true;
      if (this.form.file != "") {
        this.$refs.uploadExcel.clearFiles();
        this.form.file = "";
      }
    },
    // 文件超出个数限制时的钩子
    exceedFile(files, fileList) {
      this.$notify.warning({
        title: "警告",
        message: `只能选择 ${
          this.limitNum
        } 个文件，当前共选择了 ${files.length + fileList.length} 个`
      });
    },
    // 文件状态改变时的钩子
    fileChange(file, fileList) {
      this.form.file = file.raw;
    },
    // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
    beforeUploadFile(file) {
      let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
      let size = file.size / 1024 / 1024;
      if ((extension !== "xlsx") & "xls") {
        this.$notify.warning({
          title: "警告",
          message: `只能上传Excel97-2004（即后缀是.xls）的文件`
        });
      }
    },
    // 文件上传成功时的钩子
    handleSuccess(res, file, fileList) {
      this.$refs.uploadExcel.clearFiles();
      this.form.file = "";
      this.$notify.success({
        title: "成功",
        message: `文件上传成功,数据处理中,稍后在我的消息中查看！`
      });
    },
    // 文件上传失败时的钩子
    handleError(err, file, fileList) {
      this.$notify.error({
        title: "错误",
        message: `文件上传失败`
      });
    },
    uploadFile() {
      let formData = new FormData();
      formData.append("file", this.form.file);
      axios
        .post(this.uploadUrl, formData, {
          "Content-Type": "multipart/form-data"
        })
        .then(res => {
          if (res.data.result == 1) {
            let path = res.data.fileUrl;
            this.$api.school.myCustomerImport({ path: path }).then(res => {
              if (res.result == 2) {
                this.$message({
                  message: res.msg,
                  type: "error"
                });
                this.handleError();
              } else {
                this.$message({
                  message: res.msg,
                  type: "success"
                });
                this.handleSuccess();
              }
              this.uploadOem = false;
              this.findPage(null);
            });
          } else {
            this.handleError();
          }
        });
    },

    // 删除上传列表操作
    handleRemove(file, fileList) {
      this.form.file = "";
    },

    // 下载模板
    downloadTmpl() {
      this.getSchoolTempl();
    },

    // 获取部门数据
    get_dept_data() {
      this.$api.dropdown.deptLevel3().then(res => {
        this.deptData = res.departmentInfoList;
      });
    },

    //划分方式 控制部门人员显示
    deptmodeoptionsChange(value) {
      if (value == 9) {
        this.isShowFlag = 2;
        this.AllotData.belong_to_type = 1; //个人
        this.AllotData.thirdLevelDepartment = 0; //清空
      } else if (value == 11) {
        this.isShowFlag = 1;
        this.AllotData.belong_to_type = 2; //部门
        this.AllotData.belongToId = 0;
      } else {
        this.isShowFlag = 0;
      }
    },

    // 点击部门
    handleTreeSelectChange3Add(data, node) {
      this.deptinputValue = data.deptName;
      this.AllotData.thirdLevelDepartment = data.id;
      this.AllotData.belongToId = data.id;
      this.AllotData.belongToId = "";
      this.get_dept_user();
    },

    // 获取部门用户
    get_dept_user() {
      this.$api.student
        .queryUserList({ get_dept_user: this.AllotData.thirdLevelDepartment })
        .then(res => {
          this.deptuseroption = res.userInfoList;
        });
    },

    // 查看客户档案
    handleSee: function(params) {
      this.dataForm = Object.assign({}, params.row);
      this.$router.push({
        path: "/Customerfile/School",
        query: {
          id: this.dataForm.id
        }
      });
    },

    // 修改客户档案
    handleEdit: function(params) {
      this.dataForm = Object.assign({}, params.row);
      this.$router.push({
        path: "/Customerfile/EditSchool",
        query: {
          id: this.dataForm.id
        }
      });
    },

    // 获取选中的表格数据
    selectionChange: function(params) {
      let selectionsLength = params.selections.length;
      this.selections = params.selections;

      this.ids = [];
      let idstu = this.selections.map(item => item.id);
      this.ids = idstu;
    },

    // 新增客户
    handleNewADD: function() {
      this.$router.push({
        path: "/Customerfile/AddSchool",
        query: {
          createType: "4"
        }
      });
    },
    // 客户跟进
    handleFollow: function(params) {
      this.pageRequest2.pageNum = "1";
      this.agentName = params.row.agentName;
      this.addFollow = true;
      this.saveData.schoolId = params.row.id;
      this.saveData.trackingNum = params.row.trackingNum;
      this.saveData.name = params.row.name;
      this.saveData.contactTrack = params.row.name;
      this.saveData.communicationType = "1";
      this.saveData.type = params.row.type;
      this.saveData.progress = params.row.progress;
      this.findPage2(null);
    },
    // 报备
    handleReport: function(params) {
      this.reportShow = true;
      // this.recordData=params.row
      this.schoolVisitType();
      this.recordData.name = params.row.name;
      this.recordData.schoolId = params.row.id;
      this.recordData.feastNum = params.row.feastNum;
      this.recordData.mettingNum = params.row.mettingNum;
      this.recordData.visitNum = params.row.visitNum;
      this.recordData.belongToId = params.row.belongToId;
      this.recordData.belongToName = params.row.belongToName;

      // if (this.recordData.trackingDate.length > 0) {
      //   this.recordData.trackingDateStart = this.recordData.trackingDate[0];
      //   this.recordData.trackingDateEnd = this.recordData.trackingDate[1];
      // }
      this.findPage3(null);
    },
    // 报备类别
    schoolVisitType() {
      // this.$api.dropdown.schoolVisitType().then(res => {
      //   this.school_recordType_options = res.keyValueList;
      // });
      this.school_recordType_options = JSON.parse(
        localStorage.getItem("schoolRecordTypeOptions")
      );
    },
    // 获取地区
    handleChange(value) {
      this.schoolInfo.city = value;
    },
    handleSaveRecord() {
      if (!this.recordData.recordContent) {
        this.$message({
          message: "请输入跟踪情况！",
          type: "error"
        });
      } else {
        if (
          Array.from(this.recordData.recordContent.replace(/\s/g, "")).length <
          30
        ) {
          this.$message({
            message: "跟踪情况不得少于30字！",
            type: "error"
          });
        } else {
          this.recordData.trackingDateStart = this.recordData.trackingDate[0];
          this.recordData.trackingDateEnd = this.recordData.trackingDate[1];
          this.$api.school.saveRecord(this.recordData).then(res => {
            if (res.result == 1) {
              this.$message({
                message: res.msg,
                type: "success"
              });
              this.recordData.recordType = "";
              this.recordData.recordContent = "";
              this.recordData.nextPlan = "";
              this.recordData.majorDifficulty = "";
              this.recordData.neededSupport = "";
              this.recordData.competitor = "";
              this.recordData.charge = "";
              this.recordData.expectedClosingDate = "";
              this.recordData.plannedPeopleNum = "";
              this.reportShow = false;
            } else {
              this.$message({
                message: res.msg,
                type: "error"
              });
            }
          });
        }
      }
    },
    // 提交跟进数据
    handleSave() {
      this.$api.school.saveTrack(this.saveData).then(res => {
        if (res.result != 1) {
          this.$message({
            message: res.msg,
            type: "error"
          });
        } else {
          this.$message({
            message: res.msg,
            type: "success"
          });
          this.addFollow = false;
          this.saveData.progress = "";
          this.saveData.type = "";
          this.saveData.nextTrackingDate = "";
          this.saveData.communicationContent = "";
          this.saveData.communicationType = "";
          this.saveData.contactTrack = "";
          this.findPage(null);
        }
      });
    },
    // 获取时间
    dateFormat: function(time) {
      var date = new Date(time);
      var year = date.getFullYear();
      /* 在日期格式中，月份是从0开始的，因此要加0
       * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
       * */
      var month =
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1;
      var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      var hours =
        date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
      var minutes =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
      var seconds =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      // 拼接
      return (
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hours +
        ":" +
        minutes +
        ":" +
        seconds
      );
    },
    // 沟通形式
    get_contractType() {
      this.$api.school.school_communication_type().then(res => {
        this.student_communication_type = res.keyValueList;
      });
      this.saveData.belongToName = this.trackingPeople;
    },
    // 关闭索要弹窗
    colsePop(val) {
      this.checkrepeatShow = false;
    },
    openAsking() {
      this.checkrepeatShow = true;
    },
    Proportion(val) {
      if (val != 0) {
        if (val > 100) {
          this.$message({
            message: "请输入正确的分成比例！",
            type: "error"
          });
          this.queryBox.thirdProportion = 0;
          return false;
        }
        this.queryBox.thirdProportion = val;
        this.isSffc = !this.isSffc;
      } else if (val == 0 || val > 100 || val == "") {
        this.isSffc = !this.isSffc;
        this.queryBox.thirdProportion = 0;
      }
    },
    // 大区经理远程搜索
    querySearchAsync2(queryString, callback) {
      let restaurants = [{}];
      let results = "";
      this.$api.student.querySignRep().then(res => {
        let signRepListJson = [];
        for (let i = 0; i < res.signRepList.length; i++) {
          let j = {};
          j.name = res.signRepList[i];
          signRepListJson.push(j);
        }
        for (let i of signRepListJson) {
          i.value = i.name; //将想要展示的数据作为value
        }
        restaurants = signRepListJson;
        results = queryString
          ? restaurants.filter(this.createFilter2(queryString))
          : restaurants;
        callback(results);
      });
    },
    createFilter2(queryString) {
      return restaurant => {
        return (
          restaurant.name.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        );
      };
    },
    handleSelect2(item) {
      console.log(item);
      this.queryBox.belongToId = item.id;
    },
    //三级部门改变
    changeThree: function(value) {
      this.queryBox.thirdLevelDepartment = value;
    },
    // 获取三级部门
    get_threeDept() {
      this.$api.dropdown.deptLevel3School().then(res => {
        this.threeDept = res.departmentInfoList;
      });
      this.$api.dropdown.users({ userType: 3, deptType: 4 }).then(res => {
        if (res.result == 1) {
          this.userName = res.userInfoList;
        }
      });
    },
    // 审核通过
    handleAudit(params){
      this.$confirm('确定审核通过？','提示',{
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(()=>{
        this.$api.school.auditSchool({schoolId:params.row.id,auditStatus:3}).then(res=>{
        if (res.result == 1) {
          this.$message({
            message: res.msg,
            type: "success"
          });
        this.findPage(null)
        } else {
          this.$message({
            message: res.msg,
            type: "error"
          });
        }
      })
      })
      
    },
    // 审核驳回
    handleAudit2(params){
      this.$confirm('确定驳回审核？','提示',{
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(()=>{
        this.$api.school.auditSchool({schoolId:params.row.id,auditStatus:4}).then(res=>{
        if (res.result == 1) {
          this.$message({
            message: res.msg,
            type: "success"
          });
        this.findPage(null)
        } else {
          this.$message({
            message: res.msg,
            type: "error"
          });
        }
      })
      })
      
    }
  },
  mounted() {
    this.get_student_type();
    this.get_student_data_from();
    this.get_student_data_from_type();
    this.get_student_progress();
    this.get_level_cache();
    this.get_dept_data();
    this.get_dataTime();
    this.get_contractType();
    this.get_threeDept();
  }
};
</script>
<style>
@import url("../../assets/queryBox.css");
</style>
<style lang="scss" scope>
.add-btns .el-button:nth-child(1) {
  margin-right: 10px;
}
.second-contain-box {
  width: 95%;
  margin: 0 auto;
  .el-col {
    text-align: left;
    margin: 4px 0;
  }
  .el-row {
    margin: 0 0 !important;
  }
  .el-col i {
    font-style: normal;
    display: inline-block;
  }
}
.second-contain-box2 {
  .el-col i {
    margin-top: 0px !important;
  }
}
.schoolBoxCont {
  margin: 5px 5px;

  .schoolBoxContItem {
    margin-right: 10px;
    float: left;
    .el-form-item__content {
      display: flex;
      flex-direction: row;
    }
    .schoolBoxContItemTitle {
      background: #f5f7fa;
      width: 115px;
      border: 1px solid #dcdfe6;
      border-top-left-radius: 4px;
      border-bottom-left-radius: 4px;
      line-height: 39px;
      border-right: none;
    }
    .schoolBoxContItemInput {
      width: 150px;
      line-height: 39px;
      .el-date-editor.el-input,
      .el-date-editor.el-input__inner {
        width: 100%;
      }
    }
  }
}
</style>
